<?php
//include_once("model/itemConfig.php");
//var_dump($organization->getAuthorized());
		    global $itemType;
			global $itemTopSize;
			global $itemSize;
			global $itemColor;
			global $itemMaterial;
			global $itemSeason;
			global $itemYear;
			global $itemType;
			global $itemDesigner;
			global $organizationType;
		
/*
array(3) {
	 [0]=> array(5) {
	 	 ["id"]=> string(2) "10"
	 	 ["orid"]=> string(1) "1" 
	 	 ["number"]=> string(1) "9"
	 	  ["time_stamp"]=> string(19) "2012-10-02 11:52:33" 
	 	  ["item"]=> object(Item)#8 (11)
	 	   {
	 	  	 ["scan_code"]=> string(14) "100121001W3508"
	 	  	 ["product_code"]=> string(10) "100121001W" 
	 	  	 ["designer_code"]=> string(6) "O10001" 
	 	  	 ["type"]=> string(2) "10" 
	 	  	 ["year"]=> string(3) "012" 
	 	  	 ["season"]=> string(1) "1" 
	 	  	 ["flow"]=> string(3) "001" 
	 	  	 ["material"]=> string(1) "W" 
	 	  	 ["color"]=> string(2) "35" 
	 	  	 ["size"]=> string(2) "08" 
	 	  	 ["designer"]=> string(1) "O"
	 	  	  } 
	 }
	 [1]=> array(5) { ["id"]=> string(2) "11" ["orid"]=> string(1) "1" ["number"]=> string(3) "100" ["time_stamp"]=> string(19) "2012-10-02 12:01:20" ["item"]=> object(Item)#9 (11) { ["scan_code"]=> string(14) "100121001W010F" ["product_code"]=> string(10) "100121001W" ["designer_code"]=> string(6) "O10001" ["type"]=> string(2) "10" ["year"]=> string(3) "012" ["season"]=> string(1) "1" ["flow"]=> string(3) "001" ["material"]=> string(1) "W" ["color"]=> string(2) "01" ["size"]=> string(2) "0F" ["designer"]=> string(1) "F" } } 
	 [2]=> array(5) { ["id"]=> string(2) "12" ["orid"]=> string(1) "1" ["number"]=> string(1) "2" ["time_stamp"]=> string(19) "2012-10-03 08:34:26" ["item"]=> object(Item)#10 (11) { ["scan_code"]=> string(14) "800122333S0502" ["product_code"]=> string(10) "800122333S" ["designer_code"]=> string(6) "O80333" ["type"]=> string(2) "80" ["year"]=> string(3) "012" ["season"]=> string(1) "2" ["flow"]=> string(3) "333" ["material"]=> string(1) "S" ["color"]=> string(2) "05" ["size"]=> string(2) "02" ["designer"]=> string(1) "D" } } }
*/
?>
	<div class="block">

	<div class="invertedshiftdown">
<ul>
	<?php
	if($organization->type=='s'){
	?>
			<li><a href="?page=organization_inventory&id=<?php echo $organization->id; ?>">查看货存</a></li>
			<li class="current"><a href="?page=organization_sell&id=<?php echo $organization->id; ?>">出售</a></li>
			<li><a href="?page=organization_return&id=<?php echo $organization->id; ?>">退款</a></li>
			<li><a href="?page=organization_distribute&id=<?php echo $organization->id; ?>">分配</a></li>
			<li><a href="?page=organization_distribute_confirm&id=<?php echo $organization->id; ?>">处理待定分配</a></li>
			<li><a href="?page=organization_transaction&id=<?php echo $organization->id; ?>">查看物流记录</a></li>
			<li><a href="?page=organization_sell_record&id=<?php echo $organization->id; ?>">查看销售记录</a></li>
	<?php
	}elseif($organization->type=='w'){
	?>
	       	<li><a href="?page=organization_inventory&id=<?php echo $organization->id; ?>">查看库存</a></li>
			<li><a href="?page=organization_stack&id=<?php echo $organization->id; ?>">入库</a></li>
			<li><a href="?page=organization_distribute&id=<?php echo $organization->id; ?>">分配</a></li>
			<li><a href="?page=organization_distribute_confirm&id=<?php echo $organization->id; ?>">处理待定分配</a></li>
			<li><a href="?page=organization_transaction&id=<?php echo $organization->id; ?>">查看物流记录</a></li>
			
    <?php
	}
	?>
</ul>




<form id="myform">
<input type="text" class="textinput" /> <input class="submit" type="submit" value="搜索" />
</form>
</div>

<br style="clear: both;" />
<div id= 'content'>

	<h2><?php echo $organization->name ?> 》销售界面</h2>
		<?php
	//print_r($_GET);
	if(isset($_GET['stat'])){
		if($_GET['stat']=='sold'){
	?>
	<div id="message">
		<h4>操作成功：</h4>出售
	</div>
	
	<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='limit'){
	?>
	<div id="message_error">
		<h4>操作失败：</h4>无法出售（货存数量有限）
	</div>
    <?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='missing'){
	?>
	<div id="message_error">
		<h4>操作失败：</h4>无法出售（缺省必要参数）
	</div>
	
		<?php
		}elseif($_GET['stat']=='error'&&$_GET['error']=='badData'){
	?>
	<div id="message_error">
		<h4>操作失败：</h4>无法出售（提交了无效数据）
	</div>
<?php

		}
}
?>
	<br>
		<h4><?php echo $organization->name ?>库存显示</h4>
<form action="api/" method="post">
        	<input type="hidden" id='action' name="action" value="organization_sell" />
        	<input type="hidden" id='user1' name="user1" value="<?php echo $currentUser->id ?>" />
        	<input type="hidden" id='source' name="source" value="<?php echo  $organization->id ?>" />        	
	<table class="contentTable" border="1">
			<tbody><tr  class="solid">
		<td>选择</td>
		<td>数量</td>
		<td>扫描条码</td>
		<td>生产款号</td>
		<td>设计版号</td>
		<td>类型</td>
        <td>年份</td>
		<td>季节</td>
		<td>流水号</td>
		<td>面料</td>
		<td>色彩</td>
		<td>尺寸</td>
		<td>设计师</td>
		<td>原价</td>
		<td>折率</td>
		<td>现售与否</td>
		<td>产品名</td>

		</tr>
	
       
		<?php
		//global $auth;
		//print_r($auth);
		  //  global $organizationType;
			//		print_r($organizationType);
			
		foreach($organization->getInventory() as $inv){
			
			$type=$inv['item']->type;
			$year=$inv['item']->year;
			$season=$inv['item']->season;
			$material=$inv['item']->material;
			$size=$inv['item']->size;
			$color=$inv['item']->color;
			$designer=$inv['item']->designer;
		?>
		<tr>
		<td><input type="radio" name="inv_id" value="<?php echo $inv['id']?>"checked><?php echo $inv['id']?></input></td>	
		<td><?php echo $inv['number']?></td>
		<td><?php echo $inv['item']->scan_code ?></td>
		<td><?php echo $inv['item']->product_code ?></td>
		<td><?php echo $inv['item']->designer_code ?></td>
		<td><?php echo $itemType[$type] ?></td>
		<td><?php echo $itemYear[$year] ?></td>
		<td><?php echo $itemSeason[$season] ?></td>
		<td><?php echo $inv['item']->flow ?></td>
		<td><?php echo $itemMaterial[$material] ?></td>
		<td><?php echo $itemColor[$color] ?></td>
		<td><?php echo $itemSize[$size] ?></td>
		<td><?php echo $itemDesigner[$designer] ?></td>
		
				<td><?php echo $inv['item']->price;?></td>	
		<td><?php echo $inv['item']->ratio."%";?></td>	
		<td><?php echo ($inv['item']->active==1) ? '是' : '否';?></td>	
		
		<td><?php echo $inv['item']->name ?></td>

		</tr>

	
	<?php
		}
	?>
		</tbody></table>
		<br>
<br>

   
    	<h4>方法一，选择以上的其中一种产品,然后再填写数量和金额</h4>
    	<div class="important">若所出售产品的条形码若没能在上面列表找到请联络管理员</div>
    	<br>
              <div class="element" style="clear:both;">
              	<input type="radio" name="val" value="unit" checked>单价</input>
              	<input type="radio" name="val" value="total">总价</input>
               <label class="form">金额</label>
             <input type="text" name="amount" value="" ><div class="important">若为空，则按官方定价算</div>
             </div>
              <div class="element" style="clear:both;">
               <label class="form">数目</label>
             <input type="text" name="number" value="1" >
             </div>
             <?php
if(count($organization->getInventory())){
             ?>
             <div class="element" style="clear:both;">
             <input type="submit" value="出售" />
             </div>
             <?php
}else{
             ?>
             <div class="element" style="clear:both;">
             <input type="submit" value="出售" disabled />
             </div>
             <?php
}
             ?>
		    </form>


		    <hr>

<form action="api/" method="post">
        	<input type="hidden" id='action' name="action" value="organization_sell" />
        	<input type="hidden" id='user1' name="user1" value="<?php echo $currentUser->id ?>" />
        	<input type="hidden" id='source' name="source" value="<?php echo  $organization->id ?>" />        	

   
    	<h4>方法二，直接输入要出售的扫描条形码（无需选择表中任何库存）</h4>
    	<div class="important">若输入的扫描条形码不在库存中，此出售会失败</div>
    	<br>
    	     <div class="element" style="clear:both;">
               <label class="form">扫描条形码</label>
             <input type="text" name="scan_code" maxlength="14" size="14" >
             </div>
              <div class="element" style="clear:both;">
              	<input type="radio" name="val" value="unit" checked>单价</input>
              	<input type="radio" name="val" value="total">总价</input>
               <label class="form">金额</label>
             <input type="text" name="amount" value="" ><div class="important">若为空，则按官方定价算</div>
             </div>
              <div class="element" style="clear:both;">
               <label class="form">数目</label>
             <input type="text" name="number" value="1" >
             </div>
             <?php
if(count($organization->getInventory())){
             ?>
             <div class="element" style="clear:both;">
             <input type="submit" value="出售" />
             </div>
             <?php
}else{
             ?>
             <div class="element" style="clear:both;">
             <input type="submit" value="出售" disabled />
             </div>
             <?php
}
             ?>
		    </form>

<br>
<br>
<br>
   
<div class="clear"></div>
	</div>